function afterAddDuznici(response){
	//ypAjaxForm('<div class="area">'+response+'</div>')
	alert(response);
	LoadRSDoc("duznici.php","setContent");
}
function onChangeOdgovor(){
	var od = document.getElementById("odgovor_dana");
	var id = parseInt(document.getElementById("odgovor").value);
	if(id==6){
		od.style.display = "block"
	}else{
		od.style.display = "none"
	}
}
function duzniciSetOdgovor(id, name){
	var objid = document.getElementById("odgovor");
	var objname = document.getElementById("odgovor_name");
	objid.value = id;
	objname.value = name;
	objname.setAttribute("defaultValue",name);
	onChangeOdgovor();
}
function duzniciAlarms(a){
	var ol = a.nextSibling.nextSibling;
	var olstat = (ol.style.display=="block")?1:0;
	
	if(olstat){
		ol.style.display="none";
	}else{
		LoadRSDoc("duznici.php?a=alarm","duzniciUpdateAlarms");
	}
}
function duzniciUpdateAlarms(response){
	var al = document.getElementById("duznici_alarms");
	var a = document.getElementById("alarm_link");
	var ol = a.nextSibling.nextSibling;
	
	if(response==0){
		al.style.display="none";
	}else{
		var tmp = response.split(/\{!\}/);
		a.value = tmp[0];
		ol.innerHTML = tmp[1];
		ol.style.display="block";
		al.style.display="block";
	}
}
function duzniciUpdateKomitentDetails(komid,update){
	if(update==1){
		document.getElementById("komitent_details").innerHTML = komid;
	}else{
		var komid = document.getElementById("komitent_id").value;
		LoadRSDoc("rokovnik.php?a=komDetails&id="+komid+"&checkfox=0","duzniciUpdateKomitentDetails(1)");
	}
}
function duzniciCallhistory(response,update){
	if(update==1){
		var tmp = response.split(/\{!\}/);
		var num = parseInt(tmp[0]);
		var ch = document.getElementById("duzniciCallHistoryList");
		if(num>0){
			ch.innerHTML = tmp[1];
			ch.style.display='block';
		}else{
			ch.style.display='none';
		}
	}else{
		var komid = document.getElementById("komitent_id").value
		LoadRSDoc("duznici.php?a=callhistory&id="+komid,"duzniciCallhistory(1)");
	}
}
function  updateDuzniciContacts(kontakti){
	var contacts = kontakti.split(/\{!\}/);
	var sel = document.getElementById("kontakt");
	var contact_tel = sel.nextSibling.nextSibling;
	var contact_other = contact_tel.nextSibling.nextSibling;
	var opt;
	var slctd=false;
	
	sel.innerHTML = "";
	opt = document.createElement("option");
	opt.value = -1;
	opt.innerHTML = "---";
	sel.appendChild(opt);
	
	if(contacts.length){
		for(var i=0; i<contacts.length; i++){
			var tmp = contacts[i].split(/\{!!\}/);
			var k = tmp[0];
			var tel = tmp[1];
			
			opt = document.createElement("option");
			opt.value = contacts[i];
			opt.title = tel;
			opt.innerHTML = k;
			if(!slctd){
				opt.selected = true;
				slctd=true;
				contact_other.style.display="none";
				contact_tel.innerHTML = tel;
			}
			sel.appendChild(opt);
		}
	}
}
function duzniciOnchangeKontakt(sel){
	var kont_tel = sel.nextSibling.nextSibling;
	var kont_other = kont_tel.nextSibling.nextSibling;
	var m = sel.value.indexOf("{!!}");
	kont_tel.innerHTML = sel.value.substr(sel.value.indexOf("{!!}")+4);
	if(m>=0){
		kont_other.style.display='none';
	}else{
		kont_other.style.display='block'
	}
}
function displayDuzniciNapomena(btn){
	//alert(\''.preg_replace('/\r*\n/',"{!nl!}",$_napomena).'\'.replace(/\{!nl!\}/g,\'\\n\'))
	var obj = btn.nextSibling;
	if(obj.id.match(/^napomena_/i)){
		alert(obj.value)
	}
}
function duzniciCopyTableRow(tr,tableID){
	var TLtable = document.getElementById(tableID);
	var TLtableBody = TLtable.getElementsByTagName("tbody")[0];
	
	var ntr = tr.cloneNode(true);
	var tds = ntr.getElementsByTagName("td");
	var len = tds.length;
	for(var i=1; i<3; i++){
		ntr.removeChild(tds[len-i]);
	}
	var ntd = document.createElement("td");
	ntd.innerHTML = '<a href="javascript:void(0);" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode)">obrisi</a>';
	ntr.appendChild(ntd);
	
	//TLtable.appendChild(ntr);
	TLtableBody.appendChild(ntr);
}
function duzniciTaskListRemoveDuplicates(tblID){
	var t = document.getElementById(tblID);
	var tb = t.getElementsByTagName("tbody")[0];
	var ugo=Array();
	var trs = t.getElementsByTagName("tr");
	for(var i=1; i<trs.length; i++){
		var tds = trs[i].getElementsByTagName("td");
		//alert(tds[0].innerHTML+"\n"+ugo);
		if(ugo.indexOf(tds[0].innerHTML)>=0){
			tb.removeChild(trs[i]);
			i--;
		}else{
			ugo.push(tds[0].innerHTML);
		}
	}
}
function duzniciTaskListRemoveAll(tbody){
	var trs = tbody.getElementsByTagName("tr");
	for(var i=1; i<trs.length; i++){
		tbody.removeChild(trs[i]);
		i--;
	}
}